package com.dididoctor.doctor.Activity.Main;

import android.content.Context;

import com.dididoctor.doctor.Activity.ConstantValue;
import com.dididoctor.doctor.Bean.Token;
import com.dididoctor.doctor.Http.MyHttpResponseHandler;
import com.dididoctor.doctor.MV.BasePresenter;
import com.dididoctor.doctor.MV.BusinessClient;
import com.dididoctor.doctor.MV.Response;
import com.dididoctor.doctor.Utils.Util;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;


/**
 * @version 2.0
 * @类描述：
 * @项目名称：ddgh
 * @类名称： xmppPresenter
 * @包名称： com.dididoctor.patient.Activity.Consult
 * @创建人： zhanjunjie
 * @创建时间：2016/4/7 11:05
 * @修改人：
 * @修改时间：2016/4/7 11:05
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class ConsultPresenter extends BasePresenter {

    private ConsultView view;

    public ConsultPresenter(Context context, ConsultView view) {
        super(context, view);
        this.view = view;
    }


    public void getdoctorInfo() {
        RequestParams params = new RequestParams();
        params.put("userId", Token.getUserId());
        params.put("token", Token.getToken());
        BusinessClient.post(ConstantValue.mainPage, params, new MyHttpResponseHandler() {
                    private String hasDoctor = "";//是否有签约医生1有0没有

                    @Override
                    public void onMyResponse(Response response) {
                        if (response.isSucceed()) {
                            Consult doctor = new Consult();
                            doctor.setUserId(Util.toString(response.getString("userId")));
                            doctor.setOnline(Util.toString(response.getString("online")));
                            doctor.setIsSign(Util.toString(response.getString("isSign")));
                            doctor.setCallSwitch(Util.toString(response.getString("callSwitch")));
                            doctor.setHeadPic(Util.toString(response.getString("headPic")));
                            doctor.setName(Util.toString(response.getString("name")));
                            doctor.setPhone(Util.toString(response.getString("phone")));
                            doctor.setQrcode(Util.toString(response.getString("qrcode")));
                            doctor.setEvaluate(Util.toString(response.getString("evaluate")));
                            doctor.setSignNum(Util.toString(response.getString("signNum")));
                            doctor.setPosition(Util.toString(response.getString("position")));
                            doctor.setAccId(Util.toString(response.getString("accId")));
                            doctor.setAccPwd(Util.toString(response.getString("accPwd")));
                            doctor.setToken(Util.toString(response.getString("token")));
                            doctor.setHospitalId(Util.toString(response.getString("hospitalId")));
                            view.getdoctorsucced(doctor);
                        } else {
                            view.showToastMessage(response.getMsg());
                        }

                    }

                    @Override
                    public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                        super.onFailure(i, headers, bytes, throwable);
                        view.getdoctorfail();
                    }
                }

        );
    }


    public void updatestatus(final String type, final String status) {
        RequestParams params = new RequestParams();
        params.put("userId", Token.getUserId());
        params.put("token", Token.getToken());
        params.put("type", type);
        params.put("status", status);
        BusinessClient.post(ConstantValue.doctorswitch, params, new MyHttpResponseHandler() {

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    view.updatestatesucced(type, status);
                } else {
                    view.showToastMessage(response.getMsg());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.updatestatefail();
            }
        });
    }

}
